Skip to content

Error handling cleanup in solvers/flattening #2897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

danpoe
Copy link
Contributor

@danpoe danpoe commented Sep 4, 2018

Error handling cleanup in solvers/flattening, files array.cpp to boolbv_cond.cpp (alphabetically).

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR failed Diffblue compatibility checks (cbmc commit: 40617c9).
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to lift up invariants as far as possible. Several proposals below.


const exprt &op0=expr.op0();
DATA_INVARIANT(
op0.type() == type, "add/sub with mixed types:\n" + expr.pretty());

bvt bv=convert_bv(op0);

if(bv.size()!=width)
throw "convert_add_sub: unexpected operand 0 width";
INVARIANT(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say a CHECK_RETURN would do.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But really: we are doing this all the time. Couldn't we just make convert_bv take a second argument expected_width and do that check itself? This will also take the error reporting one step closer to where the error occurred, helping to fix root causes, not symptoms.

@@ -69,17 +76,21 @@ bvt boolbvt::convert_add_sub(const exprt &expr)

const bvt &op=convert_bv(*it);

if(op.size()!=width)
throw "convert_add_sub: unexpected operand width";
INVARIANT(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CHECK_RETURN

INVARIANT(
op.size() == width,
"the width of the bitvector resulting from the expression operand should"
"be equal to the width indicated by the expression type");

if(type.id()==ID_vector || type.id()==ID_complex)
{
const typet &subtype=ns.follow(type.subtype());

std::size_t sub_width=boolbv_width(subtype);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While at it: remove the ns.follow in here, and let boolbv_width deal with possible symbol/tag types (just pass type.subtype() to boolbv_width.

@@ -91,7 +102,8 @@ bvt boolbvt::convert_add_sub(const exprt &expr)

for(std::size_t j=0; j<tmp_op.size(); j++)
{
assert(i*sub_width+j<op.size());
INVARIANT(
i * sub_width + j < op.size(), "bit index shall be within bounds");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to check this tmp_op.size()-times. We can just check this once before entering the loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The invariant is actually contained in a nested loop. It seems that the intention is also to check that we didn't mess up the index computation (e.g. by confusing i and j). How about we keep the invariant at this place and introduce a new local variable index which is set to i * sub_width + j and then use this variable in both the invariant and the array access?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that would make sense.

@@ -100,7 +112,8 @@ bvt boolbvt::convert_add_sub(const exprt &expr)

for(std::size_t j=0; j<tmp_result.size(); j++)
{
assert(i*sub_width+j<bv.size());
INVARIANT(
i * sub_width + j < bv.size(), "bit index shall be within bounds");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above: check once, before entering the loop. And then consider whether it can be checked even earlier (as soon as all variables' values are known).

@@ -31,8 +34,10 @@ bvt boolbvt::convert_complex(const exprt &expr)
{
const bvt &tmp=convert_bv(*it);

if(tmp.size()!=op_width)
throw "convert_complex: unexpected operand width";
INVARIANT(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

@@ -47,6 +52,8 @@ bvt boolbvt::convert_complex(const exprt &expr)

bvt boolbvt::convert_complex_real(const exprt &expr)
{
PRECONDITION(expr.id() == ID_complex_real);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could such an expression be introduced, with a proper API? I have no idea what that is, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be for getting the real part of a complex number. The introduction of complex_real_exprt and complex_imag_exprt has become a separate PR now: #2916.

bv.resize(width); // chop

return bv;
}

bvt boolbvt::convert_complex_imag(const exprt &expr)
{
PRECONDITION(expr.id() == ID_complex_imag);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above: introduce a new complex_imag_exprt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #2916.

bvt boolbvt::convert_concatenation(const exprt &expr)
{
PRECONDITION(expr.id() == ID_concatenation);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use concatenation_exprt as parameter to the method.

@@ -12,6 +12,8 @@ Author: Daniel Kroening, [email protected]

bvt boolbvt::convert_cond(const exprt &expr)
{
PRECONDITION(expr.id() == ID_cond);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduce a cond_exprt (whatever that is).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ID_cond is never assigned to anything, I would say remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be a list of guarded commands, but as @romainbrenguier mentioned it's not assigned anywhere. @kroening Is this still needed or can we remove ID_cond and convert_cond?

@danpoe danpoe force-pushed the refactor/error-handling-cleanup-solvers-flattening branch from 40617c9 to b9a0781 Compare September 5, 2018 16:45
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR failed Diffblue compatibility checks (cbmc commit: 40617c9).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/83782391
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

@danpoe danpoe force-pushed the refactor/error-handling-cleanup-solvers-flattening branch 4 times, most recently from ee9241e to 4e4bbe4 Compare September 10, 2018 11:46
@danpoe danpoe force-pushed the refactor/error-handling-cleanup-solvers-flattening branch from 4e4bbe4 to 8896c52 Compare September 10, 2018 16:22
@danpoe danpoe force-pushed the refactor/error-handling-cleanup-solvers-flattening branch 2 times, most recently from 01428ad to 4a82359 Compare September 11, 2018 17:34
it->var_no() != literalt::unused_var_no(),
"variable number must be different from the unused variable number",
expr.find_source_location(),
expr.pretty());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you just pass expr to INVARIANT_WITH_DIAGNOSTICS as a structured argument rather than doing pretty() here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, this was done before the irep_pretty_diagnosticst PR was merged. I think I have to do this in a few more places in the other PRs as well.

@danpoe danpoe force-pushed the refactor/error-handling-cleanup-solvers-flattening branch from 4a82359 to 7f58955 Compare September 19, 2018 11:17
@danpoe
Copy link
Contributor Author

danpoe commented Sep 19, 2018

@kroening @tautschnig @peterschrammel There's two remaining questions in this PR regarding ID_case and ID_cond expressions. Both ID_case and ID_cond do not seem to be assigned anywhere. Can those cases be removed?

@tautschnig
Copy link
Collaborator

Both ID_case and ID_cond do not seem to be assigned anywhere. Can those cases be removed?

Deferring to @kroening @peterschrammel or @mgudemann: maybe EBMC has these? I don't know about the hardware stuff...

@peterschrammel
Copy link
Member

They are both used in EBMC.

@tautschnig
Copy link
Collaborator

They are both used in EBMC.

Thanks. Could anyone with insight into that code base help out to provide code to go in std_expr.h?

@danpoe danpoe force-pushed the refactor/error-handling-cleanup-solvers-flattening branch from 7f58955 to 5f068f9 Compare September 19, 2018 15:32
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed Diffblue compatibility checks (cbmc commit: 5f068f9).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/85324861

Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good from my point of view, with some action items left.

@@ -69,7 +62,7 @@ bvt boolbvt::convert_complex_imag(const complex_imag_exprt &expr)

bvt bv = convert_bv(expr.op());

assert(bv.size()==width*2);
INVARIANT(bv.size() == width * 2, "");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing message

@@ -54,7 +47,7 @@ bvt boolbvt::convert_complex_real(const complex_real_exprt &expr)

bvt bv = convert_bv(expr.op());

assert(bv.size()==width*2);
INVARIANT(bv.size() == width * 2, "");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing message, though really you should just drop it and add the extra argument to convert_bv?

@danpoe danpoe force-pushed the refactor/error-handling-cleanup-solvers-flattening branch from 5f068f9 to 6d22293 Compare September 23, 2018 20:07
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed Diffblue compatibility checks (cbmc commit: 6d22293).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/85673016

@danpoe danpoe force-pushed the refactor/error-handling-cleanup-solvers-flattening branch from 6d22293 to af4df20 Compare September 24, 2018 13:38
Files arrays.cpp to boolbv_cond.cpp (in alphabetical order)
@danpoe danpoe force-pushed the refactor/error-handling-cleanup-solvers-flattening branch from af4df20 to 77e1b6c Compare September 24, 2018 13:43
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed Diffblue compatibility checks (cbmc commit: 77e1b6c).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/85739351

@peterschrammel
Copy link
Member

Could anyone with insight into that code base help out to provide code to go in std_expr.h?

@danpoe, could you please raise an issue with all the expressions that you would like to be added?

@danpoe
Copy link
Contributor Author

danpoe commented Sep 25, 2018

Ok, raised an issue for now for the remaining expression types: #3037

@tautschnig tautschnig merged commit f7e224b into diffblue:develop Sep 25, 2018
@danpoe danpoe deleted the refactor/error-handling-cleanup-solvers-flattening branch June 2, 2020 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants